import os
import matplotlib.pyplot as plt
import numpy as np
import cv2
from tqdm import tqdm


path = ''
file = os.listdir(path)
img_B = []
img_G = []
img_R = []
img_B_num = np.zeros(256,dtype=np.uint64)
img_G_num = np.zeros(256,dtype=np.uint64)
img_R_num = np.zeros(256,dtype=np.uint64)

for i in tqdm(file):
    img = cv2.imread(f'{path}\\{i}')
    H,W,C = img.shape
    img_B_mean = np.uint8(np.mean(img[:,:,0]))
    img_G_mean = np.uint8(np.mean(img[:,:,1]))
    img_R_mean = np.uint8(np.mean(img[:,:,2]))
    img_B.append(img_B_mean)
    img_G.append(img_G_mean)
    img_R.append(img_R_mean)
    for x in range(H):
        for y in range(W):
            img_B_num[img[x,y,0]] += 1
            img_G_num[img[x,y,1]] += 1
            img_R_num[img[x,y,2]] += 1

np.save('B.npy',img_B_num)
np.save('G.npy',img_G_num)
np.save('R.npy',img_R_num)

# img_B_num = np.load('B.npy')
# img_G_num = np.load('G.npy')
# img_R_num = np.load('R.npy')


# X = [i for i in range(len(img_B))]
# plt.figure(1)
# B = plt.plot(img_B,label='B',color='b')
# G = plt.plot(img_G,label='G',color='g')
# R = plt.plot(img_R,label='R',color='r')
# plt.scatter(X,img_B)
# plt.scatter(X,img_G)
# plt.scatter(X,img_R)
# plt.legend()
# plt.show()

plt.figure(2)
B = plt.plot(img_B_num,label='B',color='b')
G = plt.plot(img_G_num,label='G',color='g')
R = plt.plot(img_R_num,label='R',color='r')
plt.legend()
plt.show()





